﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RTUParameterConfig.Class
{
    public class Common
    {
        /// <summary>
        /// 水质传感器列表
        /// </summary>
        public static object[] WaterQualityList = new object[] {
            "在线PH传感器(DX-PH-1)",
            "在线溶解氧传感器(DX-DOG-1)",
            "在线电导率传感器(DX-DDM-1)",
            "在线浊度传感器1000NTU(DX-ZS-1)",
            "在线浊度传感器4000NTU(DX-ZS-2)",
            "在线COD传感器(DX-COD-1)",
            "在线氨氮传感器(DX-NHN-1)",
            "在线余氯传感器(DX-CL-1)",
            "在线多参数水质传感器(DX-W100-1)",
            "在线多参数水质传感器(DX-Multipro-G5)",
            "在线多参数水质传感器(BSM-2)",
            "在线ORP传感器(DX-ORP-1)"};

        /// <summary>
        /// 水位计传感器列表
        /// </summary>
        public static object[] WaterLevelList = new object[] {
            "压力水位计(DX-WYZ-1)",
            "超声波液位计(DX-WSX-1)",
            "雷达水位计30m(DX-WLX-1 30m)",
            "雷达水位计40m(DX-WLX-1 40m)",
            "雷达水位计7m(DX-WLX-2 7m)",
            "浮子水位计",
            "气泡水位计(YLN-YQS)",
            "4-20mA输入第1路",
            "4-20mA输入第2路",
            "RS-DR-N01-1电子水尺",
            "压力水位计(DX-WYZ-1-2)",
            "雷达水位计40m(BSW-RLM-4001)",
            "气泡水位计(TP-SYQ10)"};

        /// <summary>
        /// 流量计传感器列表
        /// </summary>
        public static object[] FlowmeterList = new object[] {
            "多普勒超声流量计(DX-LSX-1)",
            "明渠流量计(DX-MQ-1)",
            "雷达流量计40m(DX-LLX-1C)",
            "雷达流量计7m(DX-LLX-2C)",
            "超声波流量计(TUF-2000-S)",
            "多普勒超声流量计(ADV11EAA)"};

        /// <summary>
        /// 流速传感器列表
        /// </summary>
        public static object[] CurrentSpeedList = new object[] { "雷达流速仪(DX-LLX-1)", "多普勒超声流量计(DX-LSX-1)(仅流速)", "雷达流量计40m(DX-LLX-1C)(仅流速)", "雷达流量计7m(DX-LLX-2C)(仅流速)", "多普勒超声流量计(ADV11EAA)(仅流速)" };
        
        /// <summary>
        /// 流速传感器列表
        /// </summary>
        public static object[] CurrentSpeedList1 = new object[] { "雷达流速仪(DX-LLX-1)", "多普勒超声流量计(DX-LSX-1)(仅流速)", "多普勒超声流量计(ADV11EAA)(仅流速)" };

        /// <summary>
        /// 多流速水位计设备选择
        /// </summary>
        public static object[] WaterLevelsList = new object[] {
            "压力水位计(DX-WYZ-1)",
            "超声波液位计(DX-WSX-1)",
            "雷达水位计30m(DX-WLX-1 30m)",
            "雷达水位计40m(DX-WLX-1 40m)",
            "雷达水位计7m(DX-WLX-2 7m)",
            "浮子水位计",
            "多普勒超声流量计(DX-LSX-1)",
            "多普勒超声流量计(ADV11EAA)",
            "4-20mA输入第1路",
            "4-20mA输入第2路",
            "RS-DR-N01-1电子水尺",
            "压力水位计(DX-WYZ-1-2)",
            "雷达水位计40m(BSW-RLM-4001)",
            "气泡水位计(TP-SYQ10)"};

        /// <summary>
        /// 闸位计传感器列表
        /// </summary>
        public static object[] GatePositionList = new object[] { "闸位计(WPS-M)", "KS-10闸位计" };

        /// <summary>
        /// 雨量传感器列表
        /// </summary>
        public static object[] RainFallList = new object[] { "翻斗式雨量计(JD05)" };

        /// <summary>
        /// 水温传感器列表
        /// </summary>
        public static object[] WaterTemperatureList = new object[] { "水温传感器" };

        /// <summary>
        /// 相机传感器列表
        /// </summary>
        //public static object[] CameraList = new object[] { "LJ-DSC02系列", "尚鑫航串口相机" };
        public static object[] CameraList = new object[] { "串口相机" };

        /// <summary>
        /// 摄像头传感器列表
        /// </summary>
        public static object[] VideoList = new object[] { "海康威视网络摄像头", "大华网络摄像头" };

        /// <summary>
        /// 土壤温湿度传感器列表
        /// </summary>
        public static object[] SoilList = new object[] { "土壤温湿度传感器" };

        /// <summary>
        /// 渗压力传感器列表
        /// </summary>
        public static object[] OsmoticPressureList = new object[] { "渗压力传感器" };

        /// <summary>
        /// 风速传感器列表
        /// </summary>
        public static object[] WindSpeedList = new object[] { "风速(NHFS80BR)", "风速(DX-WS)" };

        /// <summary>
        /// 风向温湿度传感器列表
        /// </summary>
        public static object[] WindDirList = new object[] { "风向(NHFX81AR)", "风向-DX-WDZ" };

        /// <summary>
        /// 大气温湿压传感器列表
        /// </summary>
        public static object[] AtmosphereList = new object[] { "大气温湿压传感器" };

        /// <summary>
        /// 气象站(七要素)列表
        /// </summary>
        public static object[] MeteorologicalStationSevenList = new object[] { "气象站(七要素)" };

        /// <summary>
        /// PM传感器列表
        /// </summary>
        public static object[] PmList = new object[] { "GAS-PM(二合一)传感器", "PM2.5传感器","PM10传感器" };

        /// <summary>
        /// 流量计算列表
        /// </summary>
        public static object[] FlowList1 = new object[] { "水位计1", "水位1+流速1", "水位计1+闸位1", "水位计1+流量计1", "流量计1" };

        /// <summary>
        /// 流量计算列表
        /// </summary>
        public static object[] FlowList2 = new object[] { "水位计2", "水位2+流速2", "水位计2+闸位2", "水位计2+流量计2", "流量计2" };

        /// <summary>
        /// 水位截面列表
        /// </summary>
        public static object[] JmList1 = new object[] {
            "直角三角堰明渠",
            "矩形薄壁堰明渠",
            "巴歇尔槽(短喉道槽)",
            "长喉道槽(非淹没出流)",
            "非薄壁圆管自由孔流",
            "堰流流量计算","水位/流量标定表计算"};

        /// <summary>
        /// 水位+流速 水位+流量计截面列表
        /// </summary>
        public static object[] JmList2 = new object[] {
            "三角渠",
            "矩形渠",
            "梯形渠",
            "圆管",
            "U型渠",
            "自定义截面"};

        /// <summary>
        /// 水位+闸位截面列表
        /// </summary>
        public static object[] JmList3 = new object[] { "自由出流单孔闸门流量计算" };

        /// <summary>
        /// 流量计截面列表
        /// </summary>
        public static object[] JmList4 = new object[] {
            "三角渠",
            "矩形渠",
            "梯形渠",
            "圆管",
            "U型渠",
            "自定义截面",
            "直接流量输出"};

        /// <summary>
        /// 流量计截面列表
        /// </summary>
        public static object[] JmList5 = new object[] {"直接流量输出"};

        /// <summary>
        /// 水位计+多流速截面列表
        /// </summary>
        public static object[] JmList6 = new object[] { "自定义截面" };

        /// <summary>
        /// 闸位计增长方式
        /// </summary>
        public static object[] PositionDirection = new object[] { "正向增长","反向增长" };

        /// <summary>
        /// 雨量计分辨率
        /// </summary>
        public static object[] RainFallResolutionRatio = new object[] { "0.1mm", "0.2mm", "0.5mm" };

        /// <summary>
        /// 开关状态
        /// </summary>
        public static object[] OpenStatus = new object[] { "关闭", "开启" };

        /// <summary>
        /// 相机图片采集时段
        /// </summary>
        public static object[] CameraTimeInterval = new object[] {"仅白天","全天候"};

        /// <summary>
        /// 相机图片报文响应
        /// </summary>
        public static object[] CameraPicAck = new object[] {"M2模式每包带响应","M3模式最后包响应"};

        /// <summary>
        /// 相机加报上报时段
        /// </summary>
        public static object[] CameraHours = new object[] {
            "0时",
            "1时",
            "2时",
            "3时",
            "4时",
            "5时",
            "6时",
            "7时",
            "8时",
            "9时",
            "10时",
            "11时",
            "12时",
            "13时",
            "14时",
            "15时",
            "16时",
            "17时",
            "18时",
            "19时",
            "20时",
            "21时",
            "22时",
            "23时"};

        /// <summary>
        /// 摄像头叠加内容
        /// </summary>
        public static object[] VideoContentSelection = new object[] {
            "关闭",
            "自定义",
            "站点名称",
            "水位1",
            "水位2",
            "瞬时流量1",
            "瞬时流量2",
            "总瞬时流量",
            "小时流量1",
            "小时流量2",
            "设备温度",
            "设备电压",
            "采集时间",
            "刷新时间"};

        /// <summary>
        /// 流量显示类型
        /// </summary>
        public static object[] WaterFlowShowType = new object[] { "瞬时流量(m3/s)", "小时流量(m3/h)" };

        /// <summary>
        /// 流量精度选择
        /// </summary>
        public static object[] WaterFlowAccuracy = new object[] { "1L/h", "1m3/h" };

        /// <summary>
        /// 遥测站类型
        /// </summary>
        public static object[] StationType = new object[] { "降水", "河道", "水库（湖泊）", "闸坝", "泵站", "潮汐", "墒情", "地下水", "水质", "取水口", "排水口" };

        /// <summary>
        /// 工作模式
        /// </summary>
        public static object[] WorkType = new object[] { "低功耗模式", "常在线模式" };

        /// <summary>
        /// 传输协议
        /// </summary>
        public static object[] TransportProtocol = new object[] { "TCP协议","UDP协议" };

        /// <summary>
        /// 报文协议
        /// </summary>
        public static object[] ReportProtocol = new object[] { "水文SL651-2014","Http Post", "定制协议", "SZY206-2016协议","HJT212-2017协议" };

        /// <summary>
        /// 硬件接口
        /// </summary>
        public static object[] HardwareInterface = new object[] { "GPRS/3G/4G", "有线以太网", "RS485通道3透传" };

        /// <summary>
        /// 水温数据来源
        /// </summary>
        public static object[] WaterTemperatureSourcesList = new object[] { "独立水温计(DX-WS)", "水位计1", "水位计2", "流量计1", "流量计2",  "在线PH传感器",
            "在线溶解氧传感器",
            "在线电导率传感器",
            "在线浊度传感器(1000NTU)",
            "在线浊度传感器(4000NTU)",
            "在线COD传感器",
            "在线氨氮传感器",
            "在线余氯传感器",
            "在线多参数水质传感器",
            "在线ORP传感器"};

        /// <summary>
        ///RS485-3端口功能
        /// </summary>
        public static object[] Function_485_3 = new object[] { "远控输出", "迪文屏功能", "modbus从机", "LED点阵屏", "RS485通道3透传" };

        /// <summary>
        ///定时报选择
        /// </summary>
        public static object[] TimingReport = new object[] { "0", "1", "2", "3", "4", "6", "8", "12", "24"};

        /// <summary>
        /// 4~20mA输出模块型号
        /// </summary>
        public static object[] OutType = new object[] { "鸿海MB4AI4A0" };

        /// <summary>
        /// 4~20mA输出源
        /// </summary>
        public static object[] OutSelect = new object[] { "关闭", "瞬时流量1(m3/s)", "瞬时流量2(m3/s)", "流速1(m/s)", "流速2(m/s)", "水位1(m)", "水位2(m)" };

        /// <summary>
        /// 4~20mA输入源
        /// </summary>
        public static object[] InSelect = new object[] { "关闭", "水位1(m)", "水位2(m)", "流速1(m/s)", "流速2(m/s)", "瞬时流量1(m3/s)", "瞬时流量2(m3/s)" };

        /// <summary>
        /// 显示错误提示信息
        /// </summary>
        /// <param name="strMessage">提示信息</param>
        public static void ShowErrorMessage(string strMessage)
        {
            MessageBox.Show(strMessage, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        /// <summary>
        /// 显示提示信息
        /// </summary>
        /// <param name="strMessage">提示信息</param>
        public static void ShowMessage(string strMessage)
        {
            MessageBox.Show(strMessage, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        /// <summary>
        /// 两字节转int
        /// </summary>
        /// <param name="b1"></param>
        /// <param name="b2"></param>
        /// <returns>int</returns>
        public static int BytesToShort(byte b1, byte b2)
        {
            return b1 << 8 | b2;
        }

        /// <summary>
        /// 取整数的某一位
        /// </summary>
        /// <param name="resource">要取某一位的整数</param>
        /// <param name="mask">要取的位置索引，自右至左为0-7</param>
        /// <returns>返回某一位的值（0或者1）</returns>
        public static int GetIntBit(int resource, int mask)
        {
            return resource >> mask & 1;
        }

        public static string ConvertDataBySpace(Byte[] data)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                foreach (Byte b in data)
                {
                    sb.Append(Convert.ToString(b, 16).ToUpper().PadLeft(2, '0') + " ");
                }
                return sb.ToString().Trim();
            }
            catch { return string.Empty; }
        }

        public static byte[] GetByteForString(string strText, int intMaxCount)
        {
            byte[] bytes = new byte[intMaxCount];
            byte[] byteText = System.Text.Encoding.Default.GetBytes(strText);
            if (bytes.Length >= byteText.Length)
            {
                Array.Copy(byteText, 0, bytes, 0, byteText.Length);
            }
            return bytes;
        }

        public static decimal GetMintime(decimal deValue, decimal deOldValue)
        {
            decimal d = 0;
            if (deValue > 60)
            {
                d = deValue % 60;
            }
            else
            {
                d = 60 % deValue;
            }

            if (d != 0)
            {
                return deOldValue;
            }
            else
            {
                return deValue;
            }
        }
    }
}
